// pagesProperty/pages/asset/borrow/record/index.js
var app = getApp(), fetchApi = require("../../../../../utils/httpPost.js"),
formatTime = require("../../../../../component/common.js");
import Toast from '../../../../../component/vant/toast/toast';
import Dialog from '../../../../../component/vant/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: true,
    hasData: false,
    pageIndex: 1,
    pageSize: 10,
    recordList:[],
    assetId:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if(options.id){
      this.data.assetId = options.id
    }
    this.onHttpInit()
  },

  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/estate/asset/stock/taking/record', {
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
      asset_id: that.data.assetId,
    }, function (res) {
      console.log("获取资产盘点信息", res)
      if (res.data.code == 0) {
        var records = res.data.data.records;
        if(records.length > 0){
          that.data.pageIndex += 1;
          for (var index in records) {
            that.data.recordList.splice(that.data.recordList.length, 0, records[index]);
          }
          that.setData({
            hasData: true,
            recordList: that.data.recordList
          })
        }
      }else{
        Toast.fail(res.data.msg)
      }
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
      that.setData({ netWork: true, loading: true,  isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false,loading: true,  isLoading: false, })
    })
  },
   
  preImg: function (t) {
    console.log("preSunImg", t)
    var a = t.currentTarget.dataset.imageindex, e = t.currentTarget.dataset.imgdata || [];
    var c = [];
    for (var index in e) {
      c.push(e[index])
    }
    common_Js.preImg(a, c)
  },
  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.setData({
      isLoading:true,
      recordList:[],
    })
    this.onHttpInit();
  },
  /**
   * 页面上拉触底事件的处理函数    加载更多
   */
  onReachBottom: function () {
    this.onHttpInit();
  },
})